import re

def convert_chinese_numbers_to_digits(text: str) -> str:
    """
    Converts Chinese number words and spoken language ('幺') in a string to digits.
    For example, '幺八二五' becomes '1825'.
    """
    mapping = {
        "幺": "1",
        "一": "1",
        "二": "2",
        "两": "2",
        "三": "3",
        "四": "4",
        "五": "5",
        "六": "6",
        "七": "7",
        "八": "8",
        "九": "9",
        "零": "0",
    }
    # 使用正则表达式找到所有在mapping中的键，并进行替换
    # re.sub会遍历字符串，每次找到一个匹配项就调用lambda函数进行替换
    return re.sub("|".join(mapping.keys()), lambda m: mapping[m.group(0)], text)


def process_text_fn(conversation_json_data):
    conversation_text = "\n".join(
        [
            f"{item['from']}: {convert_chinese_numbers_to_digits(item['value'])}"
            for item in conversation_json_data
        ]
    )
    return conversation_text

def remove_thinking_tag(text:str) -> str:
    start = text.find("<think>")
    end = text.find("</think>")
    if start != -1 and end != -1:
        return text[:start] + text[end + len("</think>"):]
    return text


test_data = eval("""
{"call_id": "20230529135755231820-111619", "conversation": [{"from": "assistant", "value": "那个我这边是处理啊我这边处理美团生活费的，之前跟您联系过。"}, {"from": "human", "value": "哪个"}, {"from": "assistant", "value": "然后您那个美团生美团生活费。"}, {"from": "human", "value": "哦哦知道"}, {"from": "assistant", "value": "嗯嗯，你这边是什么时候能处理呀？"}, {"from": "human", "value": "哎不说下个月吗"}, {"from": "assistant", "value": "下次我知道，我就是跟您联系一下，跟您确认一下，要要不然我们这个案件就案件就要移交了。"}, {"from": "human", "value": "呃对嗯我下个月我下个月二十二十六号发工资啊"}, {"from": "assistant", "value": "哦下个月能全额处理是吧？"}, {"from": "human", "value": "呃对全额处理全额处理"}, {"from": "assistant", "value": "哦哦，好的，你的电话能打通吗？你怎么有的时候打还是空号呀？"}, {"from": "human", "value": "啊这我不知道我能打通的"}, {"from": "assistant", "value": "那你方便加个你方便加个微信吗？"}, {"from": "human", "value": "呃也可以也可以"}, {"from": "assistant", "value": "嗯对，然后我就是说跟您确认一下，要不然这个案件就移交了，你要是说能还款，我就是帮你帮你保留。"}, {"from": "human", "value": "嗯好的我下个月肯定能还下个月发工资我一次性还掉了"}, {"from": "assistant", "value": "啊。嗯，那我加一下您微信，您微信是多少？"}, {"from": "human", "value": "就手机号码"}, {"from": "assistant", "value": "手机号码中间四位是多少我看不到。幺幺三。"}, {"from": "human", "value": "五三五三五五三六八"}, {"from": "assistant", "value": "我。五三六八是呃不中间四位，不是后四位。幺三七。"}, {"from": "human", "value": "嗯五幺三七幺三七七五六九"}, {"from": "assistant", "value": "七五六九是吗？五三六八稍等一下，搜不到诶幺三七七五六九五三六八。"}, {"from": "human", "value": "哎对对对啊收不到吗"}, {"from": "assistant", "value": "嗯，搜不到，您应该是设置了。"}, {"from": "human", "value": "啊我真不知道我我叫我哥帮我弄的我不知道"}, {"from": "assistant", "value": "嗯，那你这个电话能通是吧？"}, {"from": "human", "value": "呃对能通能通肯定能通"}, {"from": "assistant", "value": "因因因为有的时候打是空号，然后就是说你及时把这个欠款给处理掉处理掉，然后就这边就没有什么特别的事情了。"}, {"from": "human", "value": "呃这这我知道这我知道嗯"}, {"from": "assistant", "value": "嗯嗯嗯嗯，好的，那我就先给你这个案件，给您保留下来啊。"}, {"from": "human", "value": "呃嗯好的好的好的"}, {"from": "assistant", "value": "嗯好，再见啊。"}]}
""")
processed_data = process_text_fn(test_data["conversation"])